#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_target_clicked()
{
    qDebug() << "移动成功！";
}

void Widget::on_pushButton_up_clicked()
{
    // 以上移为例：先获取当前的位置坐标x,y,width,height
    // 再对当前位置进行移动，以当前的rect为标准进行移动
    // 注意x是横坐标，y是纵坐标，而且是左手坐标系，并非与二维数组的定位一致
    QRect rect = ui->pushButton_target->geometry();
    //ui->pushButton_target->setGeometry(rect.x(), rect.y()-5, rect.width(), rect.height());
    // 这种写法也可以，只修改某个位置的坐标
    rect.setY(rect.y()-5);
    // 光修改坐标，是不够的，因为 高度/宽度 也会被修改
    rect.setHeight(rect.height()-5);
    ui->pushButton_target->setGeometry(rect);
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    //ui->pushButton_target->setGeometry(rect.x(), rect.y()+5, rect.width(), rect.height());
    rect.setY(rect.y()+5);
    rect.setHeight(rect.height()+5);
    ui->pushButton_target->setGeometry(rect);
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    //ui->pushButton_target->setGeometry(rect.x()-5, rect.y(), rect.width(), rect.height());
    rect.setX(rect.x()-5);
    rect.setWidth(rect.width()-5);
    ui->pushButton_target->setGeometry(rect);
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    //ui->pushButton_target->setGeometry(rect.x()+5, rect.y(), rect.width(), rect.height());
    rect.setX(rect.x()+5);
    rect.setWidth(rect.width()+5);
    ui->pushButton_target->setGeometry(rect);
}
